package edu.upenn.seas.peerreview.transport

import scala.collection.mutable
import scala.util.logging.Logged

/**
 * Enqueues messages that will be printed to console when
 * {@link TestLogger#flush()} is called.  Prints messages with a double dash
 * "--" at the start of each line.
 */
trait TestLogger extends Logged {
  def tag: String
  override def log(msg: String) = TestLogger.tagAndMesg.enqueue((tag, msg))
}

object TestLogger {
  private val tagAndMesg = new mutable.Queue[(String, String)]()
  def flush() = {
    println("--Printing all log messages--")
    tagAndMesg foreach (p => format("%-15s%s%n", "--%s--" format p._1, p._2))
    tagAndMesg clear
  }
}
